
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <md5c.h>
#include <stdio.h>
#include <sys/time.h>
#include "app_platform/cntl_info.h"
#include "app_platform/cgi_stub_cntl.h"
#include "../include/cooperatordao_stub4web_allinone.h"
#include "b2b2c/cooperator/ddo/cooperatorproddo_cooperator.h"
#include "b2b2c/cooperator/ddo/cooperatorsubproddo_cooperator.h"
#include "b2b2c/cooperator/ddo/cooperatorsetddo_cooperator.h"
#include "b2b2c/cooperator/ddo/cooperatorsubaccountddo_cooperator.h"	
#include <set>
#include "b2b2c/cooperator/ddo/cooperatorbaseinfoddo_cooperator.h"	
#include <vector>	
#include "b2b2c/cooperator/ddo/cooperatorlicenseddo_cooperator.h"	
#include "b2b2c/cooperator/ddo/cooperatormonitormodelddo_cooperator.h"

using namespace b2b2c::cooperator::dao;

void Init()
{       
	if(CCGI_STUB_CNTL->Initialize(true) != 0)
		std::cerr << "CCGI_STUB_CNTL->Init failed" << std::endl;
	CCGI_STUB_CNTL->setTimeout(10);
}
void TestUpdateCooperatorBaseInfo()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo cooperatorBaseInfoDdo;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::string outReserve = "";		
	CCooperatorDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.UpdateCooperatorBaseInfo(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		cooperatorBaseInfoDdo,
		inReserve,
		errmsg,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestGetCooperatorLicense()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	uint64_t cooperatorId = 0;
	std::set<uint8_t > licenseType;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::vector<b2b2c::cooperator::ddo::CCooperatorLicenseDdo > cooperatorLicenseDdo;
	std::string outReserve = "";		
	CCooperatorDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.GetCooperatorLicense(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		cooperatorId,
		licenseType,
		inReserve,
		errmsg,
		cooperatorLicenseDdo,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestGetCooperatorBaseInfo(uint64_t ddwCooperatorId)
{
	//TODO 如果使用配置中心来获取APP地址,请注释下

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(ddwCooperatorId);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(ddwCooperatorId);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	uint64_t cooperatorId = ddwCooperatorId;
	std::string inReserve = "";		
	std::string errmsg = "";		
	b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo cooperatorBaseInfoDdo;
	std::string outReserve = "";		
	CCooperatorDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.GetCooperatorBaseInfo(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		cooperatorId,
		inReserve,
		errmsg,
		cooperatorBaseInfoDdo,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());


	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestSetCooperatorPassWd()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	uint32_t cooperatorId = 0;
	std::string cooperatorOldPassword = "";		
	std::string cooperatorNewPassword = "";		
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::string outReserve = "";		
	CCooperatorDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.SetCooperatorPassWd(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		cooperatorId,
		cooperatorOldPassword,
		cooperatorNewPassword,
		inReserve,
		errmsg,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestCheckCooperatorPassWd()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	uint64_t cooperatorId = 0;
	std::string cooperatorPassword = "";		
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::string outReserve = "";		
	CCooperatorDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.CheckCooperatorPassWd(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		cooperatorId,
		cooperatorPassword,
		inReserve,
		errmsg,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestUpdateCooperatorLicense()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	b2b2c::cooperator::ddo::CCooperatorLicenseDdo cooperatorLicenseDdo;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::string outReserve = "";		
	CCooperatorDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.UpdateCooperatorLicense(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		cooperatorLicenseDdo,
		inReserve,
		errmsg,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
//测试主函数
int main(int argc, char** argv)
{
    //测试主流程
    // 开发人员可以根据业务需要进行顺序的调整，以期达到更好的测试效果
    // 比如，可以按照插入、选择、修改、选择、删除、选择 顺序进行处理
    //
    if(argc >= 3)
    {
        Init();
        int n = atoi(argv[1]);
        uint64_t ddwCooperatorId = 0;
        ddwCooperatorId = (uint64_t)(strtoul(argv[2], NULL, 10));

        switch(n)
        {
        case 1:
            printf("TestGetCooperatorBaseInfo()\n");
            TestGetCooperatorBaseInfo(ddwCooperatorId);
            break;
        default:
            printf("Input Error:%s",argv[1]);
            break;
        }
    }
    else
    {
        printf("\nusage: cooperatorao_tester ServiceType CooperatorId/CooperatorSubAccount(uint64)\n\n");
        printf("No[1] TestGetCooperatorBaseInfo()\n");
    }

    return 0;
}
